package List;

import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;

public class ListIteratorDemo {
    public static void main(String[] args) {
        List list = new ArrayList();
        list.add("nba");
        list.add("aaa");
        list.add("cba");
        list.add("wnba");
        list.add("wcba");
        System.out.println("使用ListIterator进行正向迭代");
        for (ListIterator it = list.listIterator(); it.hasNext();) {
            System.out.println(it.next());
        }
        System.out.println("使用ListIterator进行逆向迭代");
        for (ListIterator it = list.listIterator(list.size()); it.hasPrevious();) {
            //it.previous()表示返回集合中的上一个元素
            System.out.println(it.previous());
        }
    }
}
